package com.xw.echo.core.factory;

import com.xw.echo.core.client.EchoClient;
import com.xw.echo.core.register.HostAndPort;

import java.util.concurrent.ConcurrentHashMap;

public class EchoClientFactory {
    private static final ConcurrentHashMap<String, EchoClient> echoClientMap = new ConcurrentHashMap<>();

    private EchoClientFactory() {
        // 私有构造函数，防止外部实例化
    }

    public static EchoClient getEchoClient(HostAndPort hostAndPort) {
        return echoClientMap.computeIfAbsent(hostAndPort.getHost() + ":" +hostAndPort.getPort(), key -> new EchoClient(hostAndPort));
    }
}
